define(function() {
    return ['$scope','$location', '$interval','$timeout','$routeParams','bizProxy', function($scope,$location,$interval,$timeout,$routeParams,bizProxy) {
        $scope.$emit("top-show",'true');//顶部显示
        $scope.$emit('menuTypeLight','mine'); 	//控制底部menu高亮
        $scope.$emit('bub-menu','true'); 	//隐藏底部menu
        $scope.$emit('flag-tag','72');//显示底部文字

        $scope.showDet=false;
        $scope.noMessage='';
        var sysMessageList = new Array(),
        	busMessageList = new Array();
        
        //从localstorage中获取系统消息和业务通知消息
        var tempMessage = localStorage.getItem("firflyMessageInfo");
        if(!tempMessage){
        	//
        }else{
        	var messageList = JSON.parse(tempMessage);
        	messageList.forEach(function(v){
        		if(v.messageKind == 'system'){
        			sysMessageList.push(v);
        		}else if(v.messageKind == 'notify'){
        			busMessageList.push(v);
        		}
        	});
        }

        if($routeParams.flag==='system'){
            $scope.$emit('changeNavTitle','系统消息');
            $scope.showMessageList = sysMessageList;
            if(sysMessageList.length===0){
                $scope.noMessage='暂无系统消息'
            }
        }else if($routeParams.flag==='notify'){
            $scope.$emit('changeNavTitle','业务通知')
            $scope.showMessageList = busMessageList;
            if(busMessageList.length===0){
                $scope.noMessage='暂无业务通知'
            }
        }

        $scope.showDetail = function(data) {
            $scope.showDet=true;
            if(!data.action){
            	$scope.showAction = false;
            }else{
            	$scope.showAction = true;
            	// $scope.actionData = JSON.parse(data.action);
            	$scope.actionData = data.action;
            }
            
            
            
            $scope.detData = data;
            tempMessage = localStorage.getItem("firflyMessageInfo")
            //处理缓存的已读未读信息
            if(!tempMessage){
            	//
            }else{
            	if($routeParams.flag==='system'){
                    $scope.showMessageList.forEach(function(e){
                    	if(e.messageId == data.messageId){
                    		e.readStatus = 0;
                    	}
                    });
                }else if($routeParams.flag==='notify'){
                    $scope.showMessageList.forEach(function(e){
                    	if(e.messageId == data.messageId){
                    		e.readStatus = 0;
                    	}
                    });
                }
            	
            	
            	var messageList = JSON.parse(tempMessage);
            	for(var i=0;i<messageList.length;i++){
            		if(messageList[i].messageId == data.messageId){
            			messageList[i].readStatus = "0";
            			break;
            		}
            	}
            	localStorage.setItem("firflyMessageInfo",JSON.stringify(messageList));
            }
            readMessage(data.messageId);
        }
        
        
        /*//点击动作
        $scope.actionClick = function(url){
        	window.location = "http://"+url;
        }*/
        
        
        //标记已读消息
        function readMessage(id){
        	var headerInfo = {},bizInfo = {};
        	headerInfo.pageNum = '';
        	headerInfo.pageSize = '';
        	headerInfo.sessionId = transData.sessionId;
        	bizInfo.messageId = id;
        	
    		bizProxy.queryProxyBizData("readMessage",headerInfo,bizInfo,
    				function(tempData){//SUCCESS
    					console.log("标志已读成功");
		    			if(tempData.body != "" && tempData.body != null && tempData.body != "null" && tempData.body != "[]"){
						}
		    		},function(data){//FAIL
		    			console.log("标注失败");
		    		});
        }

        $scope.$on('backAllButtonClick',function (event) {
            if($scope.showDet){
                $timeout(function () {
                    $scope.showDet=false;
                },0)
            }else {
                history.back()
            }
        })
        $scope.$apply();
    }];
});